# _*_ coding: UTF-8 _*_
# 2020/5/4 14:56 
# PyCharm  
# Create by:LIUMINXUAN
# E-mail:liuminxuan1024@gmail.com
import cv2 as cv
import numpy as np


def LinearWindowFilter(src_img, winSize, padding_way='0'):
    # 首先判断winSize是否是奇数，不是奇数则报错退出
    if winSize % 2 == 0 or winSize == 1:
        print('winSize Error! such as:3, 5, 7, 9....')
        return None
    paddingSize = winSize // 2

    height, width = src_img.shape
    print("行数(高):%d,列数(宽):%d" % (height, width))

    # matBase = np.zeros((height + paddingSize * 2, width + paddingSize * 2), dtype=src_img.dtype)
    line = []
    rows = 0
    cols = 0
    while rows < height:
        while cols < width:
            line = src_img[rows, cols:cols + winSize]
            cols += winSize
            line_sort = sorted(line)
            print(line)
            print(line_sort)
            list_len = len(line)
            print(line[list_len//2])
    rows += 1


src_jiaoyan = cv.imread("./img/jiaoyan/xust_jiaoyan.bmp", cv.IMREAD_GRAYSCALE)
cv.imshow("src_jiaoyan", src_jiaoyan)
LinearWindowFilter(src_jiaoyan, 3)

cv.waitKey(0)
cv.destroyAllWindows()